草庐IT

python - 无法执行 collectstatic

全部标签

ruby - 我能否编写仅在我的脚本运行时执行但在需要时不执行的 Ruby 代码?

我想写一个像这样的Ruby脚本:classFoo#instancemethodsheredefself.runfoo=Foo.new#dostuffhereendend#Thiscodeshouldonlybeexecutedwhenrunasascript,butnotwhenrequiredintoanotherfileunlessrequired_in?#我希望能够对其进行单元测试,这就是为什么我不希望类外的代码运行,除非我直接执行脚本,即rubyfoo_it_up.rb。我知道我可以简单地将Foo类放在另一个文件中并在我的脚本中require'foo'。事实上,这可能是一种更好

ruby - 无法更改 RVM 默认值

我在更改默认ruby​​时遇到问题。运行OSXLion。macbook:~work$rvmlistrvmrubies=*ruby-1.9.2-p290[x86_64]ruby-1.9.2-p318[x86_64]如您所见,1.9.2-p290是默认值。macbook:~work$rvmuse--defaultruby-1.9.2-p318Using/usr/local/rvm/gems/ruby-1.9.2-p318macbook:~work$rvmlistrvmrubies*ruby-1.9.2-p290[x86_64]=>ruby-1.9.2-p318[x86_64]运行rvmus

ruby-on-rails - RVM 查找系统 gems 的可执行文件

我已经安装了RVM和ruby​​版本。但是,如果我启动控制台并运行命令railsserver、bundleinstall等。我会收到此错误bash:/usr/bin/rails:/usr/bin/ruby1.8:badinterpreter:Nosuchfileordirectory但如果我先运行rvmuse1.9.2,那么一切都正常。我尝试使用`rvmuse--default1.9.2'但没有任何改变。这是否意味着它使用的ruby与RVM中的ruby不同?提前致谢! 最佳答案 rubygemsbin文件夹和PATH的解释哦。你没有

ruby-on-rails - RMagick gem 无法在 Debian Stable 上安装

编辑:[已修复]问题是我已经安装了它,但不知道,并尝试从源代码安装。这创建了两个版本,gem不知道使用哪个。我通过转到下载的源并运行来修复它sudomakeuninstall然后我再次运行geminstallrmagick并且成功了![原始问题]我正在尝试像thisrailscast中那样安装rmagickgem.这是我放入gemfile的片段:gem'rmagick'gem'carrierwave'当我运行bundleinstall时,我得到以下输出:Installingrmagick(2.13.1)withnativeextensionsGem::Installer::Extens

ruby - nil.to_json 无法解析回 nil?

此代码段抛出异常:x=niljsoned=x.to_jsonputs'x.to_json='+jsoned.inspectputs'back='+JSON.parse(jsoned).inspectC:/ruby/lib/ruby/1.9.1/json/common.rb:146:in`parse':706:unexpectedtokenat'null'(JSON::ParserError)x.to_json="null"fromC:/ruby/lib/ruby/1.9.1/json/common.rb:146:in`parse'fromC:/dev/prototyping/appox

ruby - 在 Ruby 中执行非阻塞 I/O 的首选方式是什么?

如果说我想检索一个网页进行解析,但在I/O发生时不阻塞CPU。是否有与Python的Eventlet库等效的东西? 最佳答案 Ruby的最佳HTTP客户端库是Typhoeus,它可用于以非阻塞方式并行执行多个HTTP请求。有阻塞和非阻塞接口(interface):#blockingresponse=Typhoeus::Request.get("http://stackoverflow.com/")putsresponse.body#non-blockingrequest1=Typhoeus::Request.new("http://

ruby - HTTParty 选项参数无法正常运行

我正在设置一个可以发出LastFMAPI请求的应用程序。这些是简单的获取请求,我正在使用HTTPartygem。我的函数如下:defget_albumsself.class.base_uri"http://ws.audioscrobbler.com/2.0/"options={:user=>"Gerard1992",:method=>"user.gettopalbums",:api_key=>Constants::LASTFM_API_KEY,:format=>"json"}putsoptions.to_queryself.class.get"/?#{options.to_query}

ruby-on-rails - 如何在 Ruby on Rails 中执行期间确定 Controller 变量的值?

在执行期间确定Controller变量值的最佳方法是什么?例如,有没有办法在代码中插入一个中断,并使变量的值输出到屏幕(或日志)? 最佳答案 是的。最简单的方法是将值提升为字符串。像这样:raise@foo.to_s或者,您可以安装调试器(geminstallruby​​-debug),然后使用--debugger标志启动开发服务器。然后,在您的代码中,调用debugger指令。在调试器提示中,您有许多命令,包括打印变量值的p。更新:这里是abitmoreaboutruby-debug.

ruby-on-rails - Rails 服务器无法启动,Rails 5 中的弃用警告(MIME?Sprockets?)

我使用“railss”,但服务器无法启动。我也是刚开始当我重新启动它时,我得到了这个:=>BootingPuma=>Rails5.0.0applicationstartingindevelopmentonhttp://localhost:3000=>Run`railsserver-h`formorestartupoptionsDEPRECATIONWARNING:Sprocketsmethod`register_engine`isdeprecated.Pleaseregisteramimetypeusing`register_mime_type`thenuse`register_com

ruby - Capistrano - 无法部署我的 database.yml

当我尝试使用capistrano部署我的应用程序时,我会收到此错误:failed:"sh-c'cp/var/www/my_app/releases/20120313115055/config/database.staging.yml/var/www/my_app/releases/20120313115055/config/database.yml'"onIP_ADDR我的database.yml即空的,database.staging.yml:production:adapter:mysql2encoding:utf8reconnect:falsedatabase:my_dbpool